<template>
  <div id="app">
    <!-- 资料栏 -->
    <div class="profile">
      <van-image round class="img" fit="cover" :src="info.photo" />
      <div class="info">
        <h4 class="name">{{ info.name }}</h4>
        <span class="birth">{{ info.birthday }}</span>
      </div>
    </div>
    <!-- 连接区域 -->
    <van-row class="my_link">
      <van-col span="8">
        <van-icon name="newspaper-o"></van-icon>
        <span>我的作品</span>
      </van-col>
      <van-col span="8">
        <van-icon name="star-o"></van-icon>
        <span>我的收藏</span>
      </van-col>
      <van-col span="8">
        <van-icon name="tosend"></van-icon>
        <span>阅读历史</span>
      </van-col>
    </van-row>
    <!-- 功能区域 -->
    <van-cell-group>
      <van-cell icon="edit" title="编辑资料" is-link to="/my/edit" />
      <van-cell icon="chat-o" title="小智同学" is-link />
      <van-cell icon="setting-o" title="系统设置" is-link />
      <van-cell icon="warning-o" @click="dropout" title="退出登录" is-link />
    </van-cell-group>
  </div>
</template>

<script>
export default {
  data () {
    return {}
  },
  async created () {
    this.$store.dispatch('reqUserInfo')
  },
  computed: {
    info () {
      return this.$store.state.userInfo
    }
  },
  methods:{
    dropout(){
      // 清空token
      this.$store.commit('logout')
      this.$router.push('/login')
      this.$toast.fail('用户退出成功')
    }
  }
}
</script>

<style scoped lang="less">
#app {
  // 资料栏区域
  .profile {
    display: flex;
    align-items: center;
    height: 140px;
    background-color: #3296fa;
    .img {
      width: 92px;
      height: 92px;
      margin: 0 20px 0 22px;
    }
    .info {
      .name {
        font-weight: 700;
        font-size: 18px;
        color: white;
      }
      .birth {
        padding: 2px 4px;
        color: #3296fa;
        background-color: #fff;
        border-radius: 2px;
        font-size: 14px;
      }
    }
  }
  // 连接区域
  .my_link {
    padding: 10px 0;
    background-color: rgb(250, 250, 249);
    .van-col {
      display: flex;
      // 将主轴排列方向切换为Y轴
      flex-direction: column;
      align-items: center;
      font-size: 16px;
      .van-icon {
        font-size: 26px;
        &-newspaper-o {
          color: #8daaff;
        }
        &-star-o {
          color: #ff3800;
        }
        &-tosend {
          color: #ffaf42;
        }
      }
    }
  }
}
</style>
